package cn.xuqiudong.backend.module.common.controller;

import cn.xuqiudong.backend.base.controller.BaseBackendPuredController;
import cn.xuqiudong.backend.module.common.enums.BackendSelectEnum;
import cn.xuqiudong.common.base.model.BaseResponse;
import cn.xuqiudong.common.base.vo.Select2VO;
import org.apache.commons.io.FilenameUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 描述:
 *
 * @author Vic.xu
 * @since 2025-04-01 15:19
 */
@RestController
@RequestMapping("/common")
public class CommonController extends BaseBackendPuredController {


    /**
     * 枚举下拉框
     */
    @GetMapping("/selectEnums/{selectEnum}")
    public BaseResponse<List<Select2VO>> select(@PathVariable BackendSelectEnum selectEnum) {
        List<Select2VO> selectList = selectEnum.toSelectList();
        return BaseResponse.success(selectList);
    }

    public static void main(String[] args) {
        String fileName = "example";
        String extension = FilenameUtils.getExtension(fileName).trim();
        System.out.println("File extension: " + extension); // 输出: txt
        String blacks = ",txt,exe";
        String[] split = blacks.split(",");
        //在黑名单内则不允许上传
        for (String s : split) {
            if (s.equals(extension)) {
                System.out.println("不允许上传");
                return;
            }
        }
        System.out.println("允许上传");

    }
}
